import "../../lib/ramda.js"
import utils from "../../lib/utils.js"
import ux from "./ux.js"

const Consts = {
    STRUCT_VER: 2021,
    FPS: 25,
}

const DEFAULT_REDIS = {
    "!struct-ver": Consts.STRUCT_VER,
}

utils.redis.init()
utils.redis.Event.on_key_notfound = (k)=>{
    return DEFAULT_REDIS[k]
}

const kvs = {
    _f(t, k, v=undefined) {
        const k_fix = `[canglin]${k}`
        if (R.isNil(v)) {
            return t[k_fix]
        } else {
            t[k_fix] = v
        }
    },
    text(k, v=undefined){kvs._f(utils.redis.text, k, v)},
    number(k, v=undefined){kvs._f(utils.redis.number, k, v)},
    bool(k, v=undefined){kvs._f(utils.redis.bool, k, v)},
}
(()=>{
    if (kvs.number("!dev") < Consts.STRUCT_VER){
        utils.redis.clear()
    }
})()

ux.init(kvs)
utils.clock.frame_watch(ux.frame).start(Consts.FPS)
